package com.dongdongshop.handler;

import com.dongdongshop.data.Result;
import com.dongdongshop.enums.ResultEnum;
import com.dongdongshop.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {


    @ExceptionHandler()
    public Result exceptionHandler(UnknownAccountException ex){
        return Result.error(ResultEnum.USERNAME_PASSWORD_ERROR.getMessage());
    }

    @ExceptionHandler
    public Result exceptionHandler(IncorrectCredentialsException ex){
        return Result.error(ResultEnum.USERNAME_PASSWORD_ERROR.getMessage());
    }

    @ExceptionHandler()
    public Result exceptionHandler(BaseException ex){
        log.error("异常信息：{}", ex.getMessage());
        return Result.error(ex.getMessage());
    }


}
